Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Android SDK to v2 #522

Closed
wants to merge 12 commits into from

Conversation

louiszawadzki
Copy link
Contributor

@louiszawadzki louiszawadzki commented Sep 4, 2023

What does this PR do?

Migrate Android SDK to v2.
We always use the default instance of the SDK, later we'll see if we can allow multiple instances.

Additional Notes

iOS will follow in another PR.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@louiszawadzki louiszawadzki force-pushed the louiszawadzki/migrate-native-sdk-v2 branch from 290f6cf to e36026f Compare September 4, 2023 08:56
@louiszawadzki louiszawadzki changed the title Migrate native sdk to v2 Migrate Android SDK to v2 Sep 4, 2023
@@ -204,7 +207,6 @@ ktlint {
outputToConsole.set(true)
ignoreFailures.set(false)
enableExperimentalRules.set(false)
additionalEditorconfigFile.set(file("${project.rootDir}/script/config/.editorconfig"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this option does not exist anymore and the file did not exist

@@ -53,22 +76,38 @@ internal class DatadogSDKWrapper : DatadogWrapper {
}

override fun telemetryDebug(message: String) {
Datadog._internal._telemetry.debug(message)
// Do not initialize the telemetry proxy before SDK is initialized
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not find an easy way to test this.
It can be a bit dangerous, as if the telemetry (or webview) proxy is initialized before the SDK, then telemetry (or webview) proxy will never work.

I don't know what's the impact of re-creating a proxy on every telemetry and webview event, let me know if you think this logic is worth it or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proxy won't be recreated on every telemetry event, because lazy does initialization only once and then memoized value is returned each time.

However, maybe we can optimize isInitialized call? Datadog.isInitialized is thread-safe call, but if this safety overhead is not needed and this wrapper is called only from the single thread always, maybe we can store initialization flag directly here?

private val tracerProvider: () -> Tracer = { AndroidTracer.Builder().build() }
private val tracerProvider: () -> Tracer = {
val tracer = AndroidTracer.Builder().build()
GlobalTracer.registerIfAbsent(tracer)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is needed, need to be tested in real

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is still needed. We cannot move it behind .enable call as it was done for RUM, because GlobalTracer is not owned by us (it is coming from io.opentracing) and may be already used by the user for something else.

@louiszawadzki louiszawadzki marked this pull request as ready for review September 4, 2023 12:37
@louiszawadzki louiszawadzki requested a review from a team as a code owner September 4, 2023 12:37
Comment on lines 13 to 15
type: com.datadog.android.rum.RumActionType,
name: kotlin.String,
attributes: kotlin.collections.Map<kotlin.String, kotlin.Any?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't use FQCN directly in this file, we should use imports instead.

override fun addRumGlobalAttributes(attributes: Map<String, Any?>) {
attributes.forEach {
GlobalRum.addAttribute(it.key, it.value)
this.getRumMonitor().addAttribute(it.key, it.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: we can get rumMonitor just once, outside of forEach

Comment on lines 57 to 58
val sdkConfiguration = buildSDKConfiguration(ddSdkConfiguration)
val rumConfiguration = buildRUMConfiguration(ddSdkConfiguration)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for the naming consistency:

Suggested change
val sdkConfiguration = buildSDKConfiguration(ddSdkConfiguration)
val rumConfiguration = buildRUMConfiguration(ddSdkConfiguration)
val sdkConfiguration = buildSdkConfiguration(ddSdkConfiguration)
val rumConfiguration = buildRumConfiguration(ddSdkConfiguration)

Comment on lines +326 to +329
additionalConfig?.filterValues { it != null }?.mapValues {
it.value!!
}
?: emptyMap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: a bit strange formatting here

private val tracerProvider: () -> Tracer = { AndroidTracer.Builder().build() }
private val tracerProvider: () -> Tracer = {
val tracer = AndroidTracer.Builder().build()
GlobalTracer.registerIfAbsent(tracer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is still needed. We cannot move it behind .enable call as it was done for RUM, because GlobalTracer is not owned by us (it is coming from io.opentracing) and may be already used by the user for something else.

@@ -53,22 +76,38 @@ internal class DatadogSDKWrapper : DatadogWrapper {
}

override fun telemetryDebug(message: String) {
Datadog._internal._telemetry.debug(message)
// Do not initialize the telemetry proxy before SDK is initialized
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proxy won't be recreated on every telemetry event, because lazy does initialization only once and then memoized value is returned each time.

However, maybe we can optimize isInitialized call? Datadog.isInitialized is thread-safe call, but if this safety overhead is not needed and this wrapper is called only from the single thread always, maybe we can store initialization flag directly here?

xgouchet
xgouchet previously approved these changes Sep 5, 2023
Copy link
Member

@0xnm 0xnm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, I left some non-blocking suggestions

Comment on lines +326 to +329
additionalConfig?.filterValues { it != null }?.mapValues {
it.value!!
}
?: emptyMap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
additionalConfig?.filterValues { it != null }?.mapValues {
it.value!!
}
?: emptyMap()
additionalConfig?.filterValues { it != null }?.mapValues {
it.value!!
} ?: emptyMap()

Comment on lines +347 to +349
(configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray)
?.toArrayList() as?
List<ReadableMap>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray)
?.toArrayList() as?
List<ReadableMap>
(configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray)
?.toArrayList() as? List<ReadableMap>

override fun addRumGlobalAttributes(attributes: Map<String, Any?>) {
val rumMonitor = this.getRumMonitor()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val rumMonitor = this.getRumMonitor()
val rumMonitor = getRumMonitor()

@louiszawadzki
Copy link
Contributor Author

Closing this PR to merge directly all v2 changes in #523

@louiszawadzki louiszawadzki deleted the louiszawadzki/migrate-native-sdk-v2 branch September 20, 2023 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants